
<?PHP
if (isset ($R_MoudeTagID) || $_SESSION["User_Admin"] == 1) {
	if (!empty ($_GET["del"])) {
		if ($_GET["del"] == "1") {
			$sql = "delete from tagmodule where ID=$R_MoudeTagID";
			$_rd = mysql_query($sql, $_db_link);
			GotoURL("index.php?tag={$_GET['tag']}");
		}

	} else
		if (!empty($_GET["down"])) {
		$sql = "update tagmodule set Sorting=Sorting+1 where TagID=$tagID and Sorting=" . ($_GET["Sorting"] - 1) . " and Postion=" . $_GET["Postion"];
		$_rd = mysql_query($sql, $_db_link);
		$sql = "update tagmodule set Sorting=Sorting-1 where id=$R_MoudeTagID";
		mysql_query($sql, $_db_link);
	} else
		if (!empty($_GET["up"])) {
		$sql = "update tagmodule set Sorting=Sorting-1 where TagID=$tagID and Sorting=" . ($_GET["Sorting"] + 1) . " and Postion=" . $_GET["Postion"];
		$_rd = mysql_query($sql, $_db_link);
		$sql = "update tagmodule set Sorting=Sorting+1 where id=$R_MoudeTagID";
		mysql_query($sql, $_db_link);
	}
}
$sql = "select * from tagrol where tagid=$tagID";
$_rd = mysql_query($sql, $_db_link);
$_sw_tag = 0;
$_sw_tagEdit = 0;
while ($data = mysql_fetch_array($_rd, MYSQL_ASSOC)) {
	if (UserHatRolID($data["RolID"])) {
		$_sw_tag = 1;
		if ($data["Edit"] == 1) {
			$_sw_tagEdit = 1;
			break;
		}
	}
}
$sql = "select tagmodule.ID,tagmodule.Postion,tagmodule.Titel,tagmodule.Border,tagmodule.TitelShow,tagmodule.Setting,tagmodule.Sorting
,module.Adresse as Adresse1
,modulepage.Adresse as Adresse2
from tagmodule,module,modulepage
where tagmodule.TagID=$tagID and tagmodule.Visible=1 and tagmodule.ModuleID=module.ID and  module.MainPageID=modulepage.ID
ORDER BY sorting desc";



$L_rd = mysql_query($sql, $_db_link);
while (($data = mysql_fetch_array($L_rd, MYSQL_ASSOC)) && $_sw_tag == 1) {
	$L_data[$data["Postion"]][] = $data;
	if (!isset ($L_datalength[$data["Postion"]])) {
		$L_datalength[$data["Postion"]] = 0;
	}
	$L_datalength[$data["Postion"]]++;

}

if (!empty($L_datalength)) {
	asort($L_datalength);
}
if (!empty ($_GET['MoudeTagID'])) {
	echo '<div style="float: left;width:100%">';
	for ($L_Postion = 0; $L_Postion < 5; $L_Postion++) {
		for ($_i = 0; $_i < $L_datalength[$L_Postion]; $_i++) {
			if($_GET['MoudeTagID']==$L_data[$L_Postion][$_i]["ID"])
				include ("TitelModule.php");
		}
	}
	echo '</div>';
} else {
	for ($L_Postion = 0; $L_Postion < 5; $L_Postion++) {
		if(isset($L_datalength[$L_Postion])){
			for ($_i = 0; $_i < $L_datalength[$L_Postion]; $_i++) {
				if ($_i == 0) {
					echo '<div style="float: left;">';
				}
				include ("TitelModule.php");
				if ($_i == $L_datalength[$L_Postion] - 1) {
					echo '</div>';
				}
			}
		}
	}
}
?>